<script>
	import config from './config'
	import store from '@/store'
	import {
		getToken
	} from '@/utils/auth'
	import {
		GetAppConfig
	} from "@/api/index.js"
	import {
		getUserInfo
	} from "@/api/login.js"
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			this.initApp()
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()

				// 检查登录状态
				this.checkLogin()
			},
			initConfig() {
				// this.globalData.config = config
				GetAppConfig().then(res => {
					uni.setStorageSync('APP_CONFIG', res.data)
				})
			},
			checkLogin() {
				let openId = uni.getStorageSync('userInfo').openId
				if (!uni.getStorageSync('Authorization')) {
					uni.setStorageSync('isLogin', false)
					uni.setStorageSync('USER_TYPE', 1)
					// let url = location.href;
					// console.log(url,'app.vue');
					// uni.navigateTo({
					// 	url:'/pages/login/index?url=' + url
					// })

				} else {
					uni.setStorageSync('isLogin', true)
					getUserInfo({
						openId
					}).then(res => {
						uni.setStorageSync("userInfo", res.data)
						uni.setStorageSync('USER_TYPE', res.data.userType)
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";

	/*每个页面公共css */
	page {
		background-color: #eee;
	}
</style>